﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class ClientPCItemAccessLog : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            ClientPCItemAccessLogOutParam result = new ClientPCItemAccessLogOutParam();
            ClientPCItemAccessLogInParam param = new ClientPCItemAccessLogInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as ClientPCItemAccessLogInParam;
                if (string.IsNullOrEmpty(param.app_version) || string.IsNullOrEmpty(param.device_id) 
                    || string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.type) || string.IsNullOrEmpty(param.module_id))
                {
                    result.code = "0";
                    result.desc = "客户端类型,设备ID,用户ID,客户端版本号,模块ID不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (CommonUtils.IsDisableUsers(param.user_id))
                    {
                        result.code = "0";
                        result.desc = "用户状态有问题，请联系管理员";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    if (param.type != "1" && param.type != "2")
                    {
                        result.code = "0";
                        result.desc = "客户端类型必须为1(android)，或2(iphone)";

                        isFlag = false;
                    }
                } 
                 
                if(isFlag)
                {
                    InterfaceHelper.ClientPCItemAccessLog(param.type, param.device_id, param.app_version, param.user_id, param.module_id);
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-ClientPCItemAccessLog", SerializeHelper.JsonSerializer<ClientPCItemAccessLogInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<ClientPCItemAccessLogInParam, ClientPCItemAccessLogOutParam>();
            else
                SafeProcessRequest<ClientPCItemAccessLogInParam, ClientPCItemAccessLogOutParam>();
        }
    }

    #region 请求参数
    public class ClientPCItemAccessLogInParam
    {
        /// <summary>
        ///	客户端类型 1：android，2：iphone
        /// </summary>
        public string type
        { get; set; }  

        /// <summary>
        ///	设备ID 设备唯一标识 必须 
        /// </summary>
        public string device_id	
        { get; set; }  

        /// <summary>
        ///	客户端版本号 必须
        /// </summary>
        public string app_version
        { get; set; }  

        /// <summary>
        ///	用户ID 必须
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        ///	模块ID 1.资讯2.我的3.论坛4.群5.地图 必须
        /// </summary>
        public string module_id
        { get; set; }  
    }
    #endregion

    #region 结果参数
    public class ClientPCItemAccessLogOutParam
    {
        public ClientPCItemAccessLogOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    } 
    #endregion 
}